package com.tz.hospital.controller.pres;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tz.hospital.service.presService;
import com.tz.hospital.service.impl.presServiceImpl;

/**
 * Servlet implementation class upstaffController
 */
@WebServlet("/upstaffController")
public class upstaffController extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public upstaffController() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		presService ps=new presServiceImpl();
		int ygid=Integer.valueOf(request.getParameter("ygid")) ;
		
		String ygpower=request.getParameter("ygpower");
		String[] zh=ygpower.split("title");
		int l=zh.length;
		String fh="";
		for(int i=0;i<l;i++) {
			if(zh[i].indexOf("2rz")!=-1) {
				fh+="2rz";
			}
			if(zh[i].indexOf("2zy")!=-1) {
				fh+="2zy";
			}
			if(zh[i].indexOf("2gl")!=-1) {
				fh+="2gl";
			}
			if(zh[i].indexOf("3yk")!=-1) {
				fh+="3yk";
			}
			if(zh[i].indexOf("3jl")!=-1) {
				fh+="3jl";
			}
			if(zh[i].indexOf("4cd")!=-1) {
				fh+="4cd";
			}
			if(zh[i].indexOf("4dw")!=-1) {
				fh+="4dw";
			}
		}
		int count=ps.upstaff(ygid, fh);
		if(count>0) {
			request.getRequestDispatcher("allstaffController").forward(request, response);
		}
		System.out.println(ygid+ygpower);
		//response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
